package com.student.system.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class MD5Utils {

    private static final String MD5_KEY1="lzlg-pre";
    private static final String MD5_KEY2="lzlg-suf";
    /**
     * md5加密
     * @author wjl
     * @date 2022/12/20 15:07
     * @param src
     * @return String
     */
    private static String md5(String src){
        try {
            byte[] md5s = MessageDigest.getInstance("md5").digest(src.getBytes());
            String md5code = new BigInteger(1, md5s).toString(16);
            for (int i=0;i<32-md5code.length();i++){
                md5code="0"+md5code;
            }
            return md5code;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return  src;
    }
    /**
     * md5加密升级版本
     * @author wjl
     * @date 2022/12/20 15:07
     * @param src
     * @return String
     */
    public static String md5plus(String src){
        return md5( MD5_KEY1+md5(src)+MD5_KEY2);
    }
}
